#include "widget.h"
#include <QApplication>
bool threadflag{true};
void checkGame(Widget* tmpW){
    while(threadflag){
        DWORD processID = tmpW->Szy_GetProcessIDW(L"Stardew Valley.exe");
        if(!processID){
            tmpW->SetText("未发现游戏进程");
            tmpW->setGameProcessID(0,0);
        }
        else{
            tmpW->SetText("注入进程:"+QString::number(processID));


            if(!tmpW->getFirst()){
                tmpW->init();
                tmpW->setFirst(true);
            }
            HANDLE GameProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
            HMODULE moduleBaseAddress = tmpW->Szy_GetModuleHandleW(GameProcessHandle, L"System.Linq.dll");

            tmpW->setGameProcessID(processID, moduleBaseAddress);

            if(!moduleBaseAddress){
                tmpW->SetText1("未发现模块进程");
            }else{
                tmpW->SetText1("注入模块:"+QString::number((DWORD64)moduleBaseAddress));
            }
        }
        Sleep(500);
    }
}
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QFile file(":/QSS/Aqua.qss");
    file.open(QFile::ReadOnly);
    QString qss = file.readAll();
    file.close();
    a.setStyleSheet(qss);
    Widget w;
    std::thread t1(checkGame,&w);
    w.show();
    int ret = a.exec();
    threadflag = false;
    t1.join();
    return ret;
}
